package com.xinghai.system.service.impl;

import java.util.List;
import com.xinghai.common.utils.DateUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import com.xinghai.system.mapper.XhVehicleOrderCarHisMapper;
import com.xinghai.system.domain.XhVehicleOrderCarHis;
import com.xinghai.system.service.IXhVehicleOrderCarHisService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 订单车辆更换记录Service业务层处理
 * 
 * @author xinghai
 * @date 2024-07-23
 */
@Service
public class XhVehicleOrderCarHisServiceImpl extends ServiceImpl<XhVehicleOrderCarHisMapper, XhVehicleOrderCarHis> implements IXhVehicleOrderCarHisService
{
    @Autowired
    private XhVehicleOrderCarHisMapper xhVehicleOrderCarHisMapper;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    /**
     * 查询订单车辆更换记录
     * 
     * @param id 订单车辆更换记录主键
     * @return 订单车辆更换记录
     */
    @Override
    public XhVehicleOrderCarHis getInfo(Long id)
    {
        return xhVehicleOrderCarHisMapper.getInfo(id);
    }

    /**
     * 查询订单车辆更换记录列表
     * 
     * @param xhVehicleOrderCarHis 订单车辆更换记录
     * @return 订单车辆更换记录
     */
    @Override
    public List<XhVehicleOrderCarHis> list(XhVehicleOrderCarHis xhVehicleOrderCarHis)
    {
            xhVehicleOrderCarHis.setDelFlag("0");
        return xhVehicleOrderCarHisMapper.list(xhVehicleOrderCarHis);
    }

    /**
     * 新增订单车辆更换记录
     * 
     * @param xhVehicleOrderCarHis 订单车辆更换记录
     * @return 结果
     */
    @Override
    public int insert(XhVehicleOrderCarHis xhVehicleOrderCarHis)
    {
        xhVehicleOrderCarHis.setCreateTime(DateUtils.getNowDate());
        return xhVehicleOrderCarHisMapper.insert(xhVehicleOrderCarHis);
    }
    /**
     * 批量新增订单车辆更换记录
     *
     * @param xhVehicleOrderCarHisList 订单车辆更换记录
     * @return 结果
     */
    @Override
    public int insertBatch(List<XhVehicleOrderCarHis> xhVehicleOrderCarHisList)
    {
        return xhVehicleOrderCarHisMapper.insertBatch(xhVehicleOrderCarHisList);
    }
    /**
     * 修改订单车辆更换记录
     * 
     * @param xhVehicleOrderCarHis 订单车辆更换记录
     * @return 结果
     */
    @Override
    public int update(XhVehicleOrderCarHis xhVehicleOrderCarHis)
    {
        xhVehicleOrderCarHis.setUpdateTime(DateUtils.getNowDate());
        return xhVehicleOrderCarHisMapper.update(xhVehicleOrderCarHis);
    }

    /**
     * 批量删除订单车辆更换记录
     * 
     * @param ids 需要删除的订单车辆更换记录主键
     * @return 结果
     */
    @Override
    public int deleteBatch(Long[] ids)
    {
        return xhVehicleOrderCarHisMapper.deleteBatch(ids);
    }

    /**
     * 删除订单车辆更换记录信息
     * 
     * @param id 订单车辆更换记录主键
     * @return 结果
     */
    @Override
    public int delete(Long id)
    {
        return xhVehicleOrderCarHisMapper.delete(id);
    }

    /**
     * 导入订单车辆更换记录信息
     *
     * @param list 订单车辆更换记录信息集合
     * @return 结果
     */
    @Override
    @Transactional
    public boolean importData(List<XhVehicleOrderCarHis> list){
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        try {
            XhVehicleOrderCarHisMapper xhVehicleOrderCarHisMapper = sqlSession.getMapper(XhVehicleOrderCarHisMapper.class);
            list.stream().forEach(item -> xhVehicleOrderCarHisMapper.insert(item));
            // 提交数据
            sqlSession.commit();
            sqlSession.rollback();
        } catch (Exception e) {
            sqlSession.rollback();
            return false;
        } finally {
            sqlSession.close();
        }
        return true;
    }
}
